|
|
 |
|
|
|
|
End If
End If
End If
End Function |
|
|
|
|
|
|
|
|
The ListReposition function first checks to see whether the list box is empty. If it is, a -1 value is returned from this function. Next, it checks the value passed in to see where it is in relation to the end of the list. It first adds 1 to the current position and then compares that value with the end of the list. If it hits the end of the list, it returns the last index in the list. If it does not hit the end of the list, it moves backward by one and returns that value. However, if this number goes before the first number in the list, a 0 value is returned, which is the first element in the list. Anyway you go, youll end up with the value just prior to the one deleted as the value that will be highlighted in the list box. |
|
|
|
|
|
|
|
|
Handling an Empty Recordset |
|
|
|
|
|
|
|
|
Now lets turn our attention to what happens if there are no records in the employee table or if the user has just deleted the last row in the table. In either case, the Form_Activate() event will be called. If the user has just come into the form and the ListLoad() procedure does not load any data, the next event to be called after the Form_Load() event is the Form_Activate() event. Similarly, if the user deletes the last row and the ListReposition() function returns -1, the cmdDelete_Click event also calls the Form_Activate() event. Heres the code: |
|
|
|
 |
|
|
|
|
Private Sub Form_Activate()
Dim intResponse As Integer
If lstNames.ListCount = 0 Then
intResponse = MsgBox( _
"No Employees, " & _
"do you wish to add some?", _
vbYesNo + vbQuestion, _
"Add Records")
If intResponse = vbYes Then
Call cmdNew_Click
Else
Unload Me
End If
End If
End Sub |
|
|
|
|
|